﻿#include "mainwindow.h"
#include <QApplication>
#include <dm.h>
#include <qmessagebox.h>
#include <QProcess>
#include <QDebug>
using namespace dm;
#pragma execution_character_set("utf-8")
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    Idmsoft*  m_DM = new Idmsoft;
    bool rst = m_DM->setControl(QString::fromUtf8("{26037A0E-7CBD-4FFF-9C63-56F2D0770214}"));
        if (!rst)
        {
            // COM组件还未在系统注册，注册dm.dll，需要当前exe程序以管理员权限运行
            qDebug("Reg dm.dll");

            QString path;
            path = QCoreApplication::applicationDirPath();//获取程序运行路径
            QString cmdStr = "Regsvr32 " + path + "/dm.dll /s";
            QProcess p(0);
            p.start("cmd", QStringList() << "/c" << cmdStr);
            p.waitForStarted();
            p.waitForFinished();

            rst = m_DM->setControl("{26037A0E-7CBD-4FFF-9C63-56F2D0770214}");
            if (!rst)
            {
                QMessageBox::critical(NULL, "友情提示", "大漠插件注册失败！", QMessageBox::Yes );
            }
            else
            {
                QMessageBox::information(NULL, "友情提示", "大漠插件注册成功！", QMessageBox::Yes );
            }
        }
        else
        {
            QMessageBox::information(NULL, "友情提示", "大漠插件已经注册！", QMessageBox::Yes );
        }

        QString strInfo;
        strInfo = "当前大漠插件版本号：";
        qDebug()<<m_DM->Ver();
        qDebug()<<m_DM->Reg("d7185540adf9aecb0a6fef172db0c17eee81d32a","");
        qDebug()<<m_DM->EnumWindow(0,"大漠","",1+4+8+16);



    return a.exec();
}
